#!/usr/bin/env python3

import sys
import datetime
import os
import subprocess
import re  # 正则
import os.path

# sudo docker run --rm -it -v /home/nio/repos:/code adas-img.nioint.com/aa-sdk/cosine_orin_sud:v0.9.8

print("ready for cosine repo")

arch_type="aarch64"

ws_root_dir="/home/nio/repos"


# -------------------注释掉-------------------------------
file = open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/build.sh","r")
build_sh_text=file.read()
build_sh_text_new = build_sh_text.replace("        source deps_setup.sh $@","        # source deps_setup.sh $@")
with open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/build.sh","w") as file_new:
  print("---------------------------------------------------------edit build.sh")
  file_new.write(build_sh_text_new)
# -------------------注释掉-------------------------------

# # --------------------------------------------------
file = open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/CMakeLists.txt","r")
text=file.read()
text = text.replace("#add_subdirectory(map-engine)","add_subdirectory(map-engine)")
text = text.replace("add_subdirectory(modules)","#add_subdirectory(modules)")
with open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/CMakeLists.txt","w") as file_new:
  print("---------------------------------------------------------edit CMakeLists.txt")
  file_new.write(text)
# # --------------------------------------------------


# # --------------------------------------------------
file = open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/map-engine/CMakeLists.txt","r")
content=file.read()
content = content.replace("add_library(map_module STATIC","add_library(map_module SHARED")
content = content.replace("cmake_minimum_required(VERSION 3.14 FATAL_ERROR)","cmake_minimum_required(VERSION 3.14 FATAL_ERROR)\n\
  set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++14 -pipe -O3 -Wall -Wextra -fopenmp -fPIC -pthread -march=armv8-a+crypto\")")

with open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/map-engine/CMakeLists.txt","w") as file_new:
  print("---------------------------------------------------------edit map-engine/CMakeLists.txt")
  file_new.write(content)
# # --------------------------------------------------

# # --------------------------------------------------
file = open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/map-engine/interface/proto/CMakeLists.txt","r")
content=file.read()

content = content.replace("add_library(map_proto ${ProtoSources})","add_library(map_proto SHARED ${ProtoSources})")

with open(ws_root_dir+"/map_engine_src/map_engine_sud_provider_cosine/map-engine/interface/proto/CMakeLists.txt","w") as file_new:
  print("---------------------------------------------------------edit map-engine/interface/proto/CMakeLists.txt")
  file_new.write(content)
# # --------------------------------------------------

print("sudo docker run --rm -it -v "+ws_root_dir+":/code adas-img.nioint.com/aa-sdk/cosine_orin_sud:v0.9.8")
print("python3 /code/tool/new_map_engine_sdk/one_key_update_map_engine_sdk/3_update.py")